package com.youlai.boot.system.controller;

import com.youlai.boot.common.result.Result;
import com.youlai.boot.common.result.ResultCode;
import com.youlai.boot.system.model.QB.Safety;
import com.youlai.boot.system.model.QB.Soil;
import com.youlai.boot.system.service.SoilService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/soil")
public class SoilController {
    /**
     * 土壤水源SOP
     */
    @Autowired
    private SoilService service;

    @PostMapping("/save")
    public Result<?> saveSoil(@RequestBody Soil soil){
        return Result.judge(service.saveSoil(soil),"添加成功","添加失败");
    }
    @PostMapping("all")
    public Result<List<Soil>> getAllSoil(){
        List<Soil> documents = service.getAllSoil();
        Result<List<Soil>> result;
        if (!documents.isEmpty()) {
            result = Result.success(documents);
            result.setMessage("查询设备成功");
            result.setCode(ResultCode.SUCCESS.getCode());
        } else {
            result = Result.failed(ResultCode.SYSTEM_EXECUTION_ERROR);
            result.setMessage("查询失败，请重新查询");
        }
        return result;
    }
    @DeleteMapping("/{id}")
    public Result<?> delteSoilById(@PathVariable Integer id){
        return Result.judge(service.deleteSoilById(id),"删除成功","删除失败");
    }
}
